# -*- coding: utf-8 -*-
import os
from pysql import  *
import oss2


class Upload:
    def __init__(self,workdir):
        self.workdir=workdir;
        self.auth = oss2.Auth('LTAI20UpK915q7mg', 'eA2DpqCee5bQJNB637DdLQzOyziS1G')
        self.bucket = oss2.Bucket(self.auth, 'oss-cn-beijing.aliyuncs.com', 'classypaper')
        self.sp=mysqlOper();
    def report(self):
        files = os.listdir(self.workdir)
        xkwid='';
        topid='';
        topapername='';

        for srcpid in files:
            fpath=os.path.join(self.workdir,srcpid)
            pics=os.listdir(fpath)
            picstr = {};
            for p in pics:
                if(p.endswith('jpg')):
                    ppath=os.path.join(fpath,p);
                    with open(ppath, 'rb') as f:
                        self.bucket.put_object('remote_file.txt', f)
                        picstr.append(ppath);
                #更新数据库信息(插入paper表，更新scrapy status状态)
                self.sp.insertPaper(xkwid,topid,topapername,picstr)
            self.updateScrapyStats(xkwid);
workdir='/work/temp/xuekewang'
dd=Upload(workdir);
dd.report()




